var imgs = ["build/img/icon1-ace997ee6a.png"],
  iconArr = [{
    name: "冰箱",
    icons: ["build/img/icon_ice1-53a4024eb2.png", "build/img/icon_ice2-66793fc7f3.png", "build/img/icon_ice3-aa778d6af4.png"],
    ice_bg: ["build/img/ice_bg1-3dba25cec7.jpg", "build/img/ice_bg2-bd990d1a11.jpg", "build/img/ice_bg3-a52ebdf13f.jpg"],
    ice_wrap: ["build/img/ice_bg1-f81a3fd376.png", "build/img/ice_bg2-494c862b5f.png", "build/img/ice_bg3-f510474154.png"]
  }, {
    name: "工具",
    icons: ["build/img/icon_tool1-1d6c1a0d92.png", "build/img/icon_tool3-193b4d52e7.png"],
    items: ["build/img/tool1-2a2b05255d.png", "build/img/tool3-7415a0d3b9.png"]
  }, {
    name: "零食",
    icons: ["build/img/icon_snacks1-0f5174d428.png", "build/img/icon_snacks2-447b8e5c38.png", "build/img/icon_snacks3-1a9e0734dc.png", "build/img/icon_snacks4-ec644c5461.png", "build/img/icon_snacks5-1907668c31.png", "build/img/icon_snacks6-b26fbde1c8.png"],
    items: ["build/img/snacks1-20915bbce2.png", "build/img/snacks2-134c24f796.png", "build/img/snacks3-2ea84d9948.png", "build/img/snacks4-73ed633851.png", "build/img/snacks5-5fffeac77d.png", "build/img/snacks6-ffbbfb90e1.png"]
  }, {
    name: "肉禽",
    icons: ["build/img/icon_meat1-cebeb5dda9.png", "build/img/icon_meat2-9558be8db4.png", "build/img/icon_meat3-88fce2fde7.png", "build/img/icon_meat4-b09041208d.png", "build/img/icon_meat5-734f75cfbb.png", "build/img/icon_meat6-2da0b249d5.png", "build/img/icon_meat7-bed253c33b.png", "build/img/icon_meat8-e7389152d7.png"],
    items: ["build/img/meat1-9c035b511a.png", "build/img/meat2-8885528e97.png", "build/img/meat3-1ae09b6529.png", "build/img/meat4-dea194ceae.png", "build/img/meat5-ab4bd905c9.png", "build/img/meat6-906a810b01.png", "build/img/meat7-91d0c0368c.png", "build/img/meat8-83b6398e24.png"]
  }, {
    name: "蔬菜",
    icons: ["build/img/icon_vege1-40d45d0b84.png", "build/img/icon_vege2-708bcf8874.png", "build/img/icon_vege3-0b1f93bb76.png", "build/img/icon_vege4-4dbd4cd7cc.png", "build/img/icon_vege5-2d99836698.png", "build/img/icon_vege6-b39f8f9de6.png", "build/img/icon_vege7-3a3140081b.png", "build/img/icon_vege8-05d57c9bc2.png"],
    items: ["build/img/vege1-9e365b4c88.png", "build/img/vege2-745231f0ed.png", "build/img/vege3-4e332add53.png", "build/img/vege4-1d4c473a4e.png", "build/img/vege5-eab69ed5f2.png", "build/img/vege6-712fd5d6e8.png", "build/img/vege7-b970a0f096.png", "build/img/vege8-52edb342cb.png"]
  }, {
    name: "水果",
    icons: ["build/img/icon_fruit1-3b159b422e.png", "build/img/icon_fruit2-7b3b8432e9.png", "build/img/icon_fruit3-a4a6ae9273.png", "build/img/icon_fruit4-744635ad2e.png", "build/img/icon_fruit5-2cd43369cc.png", "build/img/icon_fruit6-26470a53f3.png"],
    items: ["build/img/fruit1-fd288578e1.png", "build/img/fruit2-fb00540246.png", "build/img/fruit3-a3660b6dcb.png", "build/img/fruit4-4defe17ef7.png", "build/img/fruit5-022995576f.png", "build/img/fruit6-a10b8c6d36.png"]
  }, {
    name: "饮品",
    icons: ["build/img/icon_drink1-0139ccb3e9.png", "build/img/icon_drink2-5d9b96afb1.png", "build/img/icon_drink3-3b1a9381c3.png", "build/img/icon_drink4-8f52e5ad80.png", "build/img/icon_drink5-d9044b21c2.png", "build/img/icon_drink6-ac7720dbeb.png", "build/img/icon_drink7-ff8a35abc3.png"],
    items: ["build/img/drink1-89ec0e1274.png", "build/img/drink2-252a02142b.png", "build/img/drink3-83c0e85a51.png", "build/img/drink4-c1febd4234.png", "build/img/drink5-580ed2fdfe.png", "build/img/drink6-60e02818a5.png", "build/img/drink7-0bcb246963.png"]
  }, {
    name: "其他",
    icons: ["build/img/icon_other1-59f0364873.png", "build/img/icon_other2-cd980c9ad3.png", "build/img/icon_other3-024d1784c3.png", "build/img/icon_other4-508e8e7edd.png", "build/img/icon_other5-c01b13c2fe.png", "build/img/icon_other6-f951924a73.png", "build/img/icon_other7-913be5e0a4.png", "build/img/icon_other8-248d423164.png", "build/img/icon_other9-3eacd9a57c.png", "build/img/icon_other10-25093b9659.png", "build/img/icon_other12-a38103536c.png", "build/img/icon_other13-86b818a578.png", "build/img/icon_other14-d1871c7cdb.png"],
    items: ["build/img/other1-b7f43610d3.png", "build/img/other2-8d3f666296.png", "build/img/other3-4aa23f6d64.png", "build/img/other4-c2fab2ac6e.png", "build/img/other5-39033201fe.png", "build/img/other6-c42b2dea12.png", "build/img/other7-de58464168.png", "build/img/other8-36a117cd91.png", "build/img/other9-1f2f6de95d.png", "build/img/other10-05dcc80da0.png", "build/img/other12-5f9d3838ce.png", "build/img/other13-37a3167ea8.png", "build/img/other14-358f48a98f.png"]
  }],
  textList = ["build/img/text1-e7b2080557.png", "build/img/text2-92b792038e.png", "build/img/text3-f51a4461c5.png", "build/img/text4-e527bd6b58.png", "build/img/text5-c61c2e0d13.png"],
  guideHideFlag = !1,
  saveShowFlag = !1,
  thingsNum = 0,
  thingOtherNum = 0,
  isiphoneX = /iphone/gi.test(navigator.userAgent) && 812 == screen.height && 375 == screen.width;
document.addEventListener("touchmove", function (i) {
  i.preventDefault()
}, {
  passive: !1
}), $(function () {
  netease.autoPlay("bgm"), loadingFn(imgs, function () {
    init()
  })
});

function init() {
  h(), e(), shareFn()
}
var HEIGHT = $(window).height() > 1030 ? $(window).height() : 1030,
  WIDTH = 640,
  Container = PIXI.Container,
  Graphics = PIXI.Graphics,
  sprite = PIXI.Sprite,
  texture = PIXI.Texture,
  loader = PIXI.loader;
loader.add(iconArr[0].ice_bg).load(p);

function p() {
  app = new PIXI.Application(WIDTH, HEIGHT, {
    backgroundColor: 16777215,
    forceCanvas: !0
  }), $("#content").append(app.view);
  var i = new Container;
  i.width = WIDTH, 
  i.height = HEIGHT;
  var e = new Graphics;
  e.beginFill(10932373), 
  e.drawRect(0, (1236 - HEIGHT) / 2, WIDTH, HEIGHT), 
  e.endFill();
  var n = new Container;
  n.width = 640, 
  n.height = 1236, 
  n.position.set(0, -(1236 - HEIGHT) / 2);
  var t = new Container;
  t.buttonMode = !0, 
  bg = sprite.fromImage(iconArr[0].ice_bg[0]), 
  t.addChild(bg), 
  t.on("tap", function () {
    for (var i = 0; i < main.children.length; i++) {
      var e = main.children[i];
      e.chosen = !1, e.outline.visible = !1
    }
  }), 
  main = new Container;
  var a = new Container;
  wrap = sprite.fromImage(iconArr[0].ice_wrap[0]), 
  a.addChild(wrap), 
  end = new Container;
  var o = new Container,
  d = sprite.fromImage("build/img/text_bg-d21999e794.png");
  d.position.set(0, 0), text = sprite.fromImage("build/img/text1-e7b2080557.png"), 
  text.position.set(48, 146), o.addChild(d, text);
  var g = sprite.fromImage("build/img/ice-b27e9d45a0.png");
  g.position.set(39, (1236 - HEIGHT) / 2 + (HEIGHT - 113));
  var c = sprite.fromImage("build/img/code-e503df1730.png");
  c.position.set(440, (1236 - HEIGHT) / 2 + (HEIGHT - 203)), end.addChild(o, c, g), end.visible = !1, n.addChild(e, t, main, a, end), n.mask = e, i.addChild(n), app.stage.addChild(i)
}

function h() {
  iconArr.forEach(function (i, e) {
    iconArr[e].icons.forEach(function (i, n) {
      var t = "<li " + (0 == n && 0 == e ? 'class = "active"' : "") + '> <div class="li_bg" style="background-image: url(' + iconArr[e].icons[n] + ');"></div><div class="li_text"></div></li>';
      $(".select_item").eq(e).children(".select_item_box").append(t)
    }), $(".select_item").eq(e).children(".select_item_box").css("width", 112 * iconArr[e].icons.length)
  })
}

function e() {
  $(".page1").addClass("ani"), isiphoneX && $(".select").addClass("iphoneX"), $(".home_btn").on("click", function () {
    $(".page1").addClass("out"), setTimeout(function () {
      $(".page1").fadeOut(), $(".guide").css("display", "block")
    }, 600)
  }), $(".guide-wrap").on("touchstart", function () {
    $(this).fadeOut()
  }), $(".scroll_bar ul li").on("click", function () {
    var i = $(this).index();
    $(".scroll_bar ul li").removeClass("selected").eq(i).addClass("selected"), $(".select-bar .black_icon").css({
      width: 0 == i ? 150 : 138,
      left: 80 * i
    }), i > 3 ? TweenMax.to($(".scroll_bar")[0], .3, {
      scrollLeft: 54
    }) : TweenMax.to($(".scroll_bar")[0], .3, {
      scrollLeft: 0
    }), $(".scroll_bar ul").css({
      width: 0 == i ? 710 : 698
    }), $(".select_item").removeClass("active").eq(i).addClass("active"), $(".select_main").hasClass("close") && ($(".select_main").removeClass("close"), $(".black_icon").show())
  }), $(".select_item").on("click", ".select_item.active li", function () {
    var i = $(this).parents(".select_item").data("id"),
      e = $(this).index();
    $(".select_item.active li").removeClass("active").eq(e).addClass("active"), saveShowFlag || ($(".save").fadeIn(), saveShowFlag = !0), 0 == i ? iceBoxChange(e) : (addThings(i, e), setTimeout(function () {
      $(".select_item.active li").removeClass("active")
    }, 300)), e > 2 && TweenMax.to($(this).parents(".select_item")[0], .3, {
      scrollLeft: 110 * (e - 2)
    })
  }), $(".select_ice").on("click", function () {
    guideHideFlag || ($(".select_guide").fadeOut(), guideHideFlag = !0)
  }), $(".arrow_bg").bind("click", function () {
    $(".select_main").hasClass("close") ? ($(".select_main").removeClass("close"), $(".black_icon").show()) : ($(".select_main").addClass("close"), $(".black_icon").hide())
  }), $(".save").on("click", function () {
    text.texture = thingOtherNum > 3 ? texture.fromImage(textList[0]) : thingsNum > 30 ? texture.fromImage(textList[4]) : thingsNum > 20 ? texture.fromImage(textList[3]) : thingsNum > 10 ? texture.fromImage(textList[2]) : texture.fromImage(textList[1]), text.texture.baseTexture.hasLoaded ? saveImg() : text.texture.baseTexture.on("loaded", function () {
      saveImg()
    }), neteaseTracker(!1, "http://minisite.click.163.com/2018/0516/womai/saveClick", "保存成功", "minisiteclick")
  }), $(".return").on("click", function () {
    reEdit()
  }), $(".btn_buy").on("click", function () {
    setTimeout(function () {
      window.location.href = "http://www.womai.com/AdvRedirect.do?uri=http://m.womai.com/nh/sale/2018-5/zzmj1805/&env=H5&mid=0&utm_source=wangyi&utm_medium=wangyi&utm_term=&utm_content=&utm_campaign=bxzz"
    }, 50), neteaseTracker(!1, "http://minisite.click.163.com/2018/0516/womai/hrefClick", "跳转按钮", "minisiteclick")
  }), moveFn($(".scroll_bar")), $(".select_item").forEach(function (i, e) {
    moveFn($(".select_item").eq(e))
  }), $(".music").addClass("on"), $(".music").on("click", function () {
    $("#bgm")[0].paused ? ($("#bgm")[0].play(), $(".music").addClass("on")) : ($("#bgm")[0].pause(), $(".music").removeClass("on"))
  })
}

function moveFn(i) {
  var e = i;
  e.mMove = !1, e.mStart = 0, e.mMove = 0, e.on("touchstart", function (i) {
    e.mMove = !0, e.mStart = i.touches[0].pageX
  }), e.on("touchmove", function (i) {
    e.mMove = i.touches[0].pageX - e.mStart, e.mMove && (console.log(e.mMove), e[0].scrollLeft -= e.mMove / 1.5), e.mStart = i.touches[0].pageX
  }), e.on("touchend", function (i) {
    e.mMove = !1
  })
}

function saveImg() {
  for (var i = 0; i < main.children.length; i++) {
    var e = main.children[i];
    e.chosen = !1, e.outline.visible = !1
  }
  end.visible = !0, $(".page2").addClass("hide"), setTimeout(function () {
    $(".end_img").attr("src", app.view.toDataURL("image/png")).show(), end.visible = !1
  }, 20)
}

function reEdit() {
  $(".page2").removeClass("hide")
}

function addThings(i, e) {
  for (var n = 0; n < main.children.length; n++) {
    var t = main.children[n];
    t.chosen = !1, t.outline.visible = !1
  }
  var a = new Container;
  a.chosen = !0, 
  a.interactive = !0, 
  a.on("touchstart", function (i) {
    var e = this;
    TweenMax.to(this.scale, .1, {
      x: 1.015,
      y: 1.015,
      onComplete: function () {
        e.scale.x = 1, e.scale.y = 1
      }
    }).yoyo(!0), this.chosen || (this.chosen = !0, this.outline.visible = !0)
  }), 
  a.data = {};
  var o = 50 * Math.random() - 50,
    d = 50 * Math.random() - 50;
  a.globalPosition = {
    x: 200 + o,
    y: 500 + d
  }, a.position.set(a.globalPosition.x, a.globalPosition.y);
  var g = sprite.fromImage(iconArr[i].items[e]);
  g.interactive = !0;
  var c = new Container;
  a.addChild(g, c), 
  a.outline = c, 
  7 == i ? (thingOtherNum++, isOther = !0) : isOther = !1, 
  g.texture.baseTexture.hasLoaded ? addThingOutline(a, isOther) : g.texture.baseTexture.on("loaded", function () {
    addThingOutline(a, isOther)
  }), 
  main.addChild(a), 
  thingsNum++
}

function addThingOutline(i, e) {
  i.outline.removeChildren(), i.isOther = e;
  var n = new Graphics;
  n.lineStyle(1, 16777215, 1);
  var t = i.width,
    a = i.height;
  i.pivot.set(t / 2, a / 2), i.position.set(i.globalPosition.x + t / 2, i.globalPosition.y + a / 2);
  n.moveTo(-20, -20), drawDashLine(n, -20, -20, t + 20, -20), drawDashLine(n, t + 20, -20, t + 20, a + 20), drawDashLine(n, t + 20, a + 20, -20, a + 20), drawDashLine(n, -20, a + 20, -20, -20), i.children[0].on("touchstart", function (e) {
    for (var n = 0; n < main.children.length; n++) {
      var t = main.children[n];
      t.chosen = !1, t.outline.visible = !1
    }
    main.removeChild(i), main.addChild(i), i.outline.visible = !0, this.dragging = !0, this.startPosition = {
      x: e.data.global.x,
      y: e.data.global.y
    }
  }).on("touchmove", function (i) {
    this.dragging && (this.newPosition = {
      x: i.data.global.x,
      y: i.data.global.y
    }, this.parent.position.set(this.newPosition.x - this.startPosition.x + this.parent.globalPosition.x + this.parent.pivot._x, this.newPosition.y - this.startPosition.y + this.parent.globalPosition.y + this.parent.pivot._y))
  }).on("touchend", function (i) {
    this.dragging = !1, this.parent.globalPosition.x = this.parent.position.x - this.parent.pivot._x, this.parent.globalPosition.y = this.parent.position.y - this.parent.pivot._y
  }).on("touchendoutside", function (i) {
    this.dragging = !1, this.parent.globalPosition.x = this.parent.position.x - this.parent.pivot._x, this.parent.globalPosition.y = this.parent.position.y - this.parent.pivot._y
  }), i.outline.addChild(n);
  var o = sprite.fromImage("build/img/rotate-241ab0e126.png");
  o.position.set(-63, -58), o.interactive = !0, o.buttonMode = !0, o.on("touchstart", function (i) {
    this.dragging = !0;
    var e = i.data.global;
    this.parent.parent.data.rotation = this.parent.parent.rotation;
    var n = ANGLE({
      x: this.parent.parent.position.x,
      y: this.parent.parent.position.y
    }, e);
    this.startRotation = n
  }).on("touchmove", function (i) {
    if (this.dragging) {
      var e = i.data.global,
        n = ANGLE({
          x: this.parent.parent.position.x,
          y: this.parent.parent.position.y
        }, e);
      this.parent.parent.rotation = n - this.startRotation + this.parent.parent.data.rotation
    }
  }).on("touchend", function () {
    this.dragging = !1
  }).on("touchendoutside", function () {
    this.dragging = !1
  });
  var d = sprite.fromImage("build/img/close-edc464535f.png");
  d.position.set(t + 20, -58), d.interactive = !0, d.buttonMode = !0, d.on("tap", function () {
    this.parent.parent.parent.removeChild(this.parent.parent), thingsNum--, this.parent.parent.isOther && thingOtherNum--
  }), i.outline.addChild(o, d)
}

function iceBoxChange(i) {
  bg.texture = texture.fromImage(iconArr[0].ice_bg[i]), wrap.texture = texture.fromImage(iconArr[0].ice_wrap[i])
}

function ANGLE(i, e) {
  var n = e.x - i.x,
    t = e.y - i.y,
    a = Math.acos(t / Math.sqrt(n * n + t * t));
  return n >= 0 && t >= 0 ? a = 2 * Math.PI - a : n >= 0 && t <= 0 && (a = 2 * Math.PI - a), a
}

function getBeveling(i, e) {
  return Math.sqrt(Math.pow(i, 2) + Math.pow(e, 2))
}

function drawDashLine(i, e, n, t, a, o) {
  o = void 0 === o ? 5 : o;
  for (var d = getBeveling(t - e, a - n), g = Math.floor(d / o), c = 0; c < g; c++) i[c % 2 == 0 ? "moveTo" : "lineTo"](e + (t - e) / g * c, n + (a - n) / g * c)
}

function loadingFn(i, e) {
  if (!i) return !1;
  for (var n = [], t = i.length, a = 0, o = 0; o < t; o++) n[o] = new Image, n[o].src = i[o], n[o].onload = function () {
    a++, $(".loading-num").html(Math.floor(a / t * 100) + "%").attr("title", Math.floor(a / t * 100)), a >= t && ($(".loading").fadeOut(600, function () {
      $(this).remove()
    }), e && e())
  }
}

function shareFn() {
  shareData = {
    MsgImg: "http://go.163.com/web/20180516_womai/shareImg/share.jpg",
    link: "http://go.163.com/web/20180516_womai/index.html",
    title: "冰箱大作战",
    desc: "你和明星的冰箱，只差一次放飞自我",
    fText: "冰箱大作战",
    callback: function () {
      share_survey(!0)
    }
  }, NeteaseShareInit()
}